-- SecondRenownRender

local ClassRef = app.mvc.createRenderClass(...)

function ClassRef.create(node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.NewBagRenownSecondNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self:setContentSize(self._ui["Panel"]:getContentSize())

	self._ui["Panel/Btn_s/Button_achieve"]:addClickEventListener(function()
			executeFunc(self._onClick, self)
			if self._data then
				if UD:isNewGotRenown( self._data.id ) then
					UD:removeFromNewGotRenown( self._data.id )
				end
				executeFunc(self.refreshRedPoint, self)
				if not cc.isDead(self._parentRender) and self._parentRender.refreshRedPoint then
					self._parentRender:refreshRedPoint()
				end
			end
		end)

	self._isSelected = false -- 是否选中、默认没有

	self._loadingBar = self._ui["Panel/Btn_s/bar/LoadingBar"]
	self._name_map = self._ui["Panel/Btn_s/name_map"]
	self._text_grade = self._ui["Panel/Btn_s/Text_grade"]
	self._num = self._ui["Panel/Btn_s/num"]

	self:refresh()
end

function ClassRef:refresh()
	if self._data then
		self._name_map:setString( self._data.name )

		local fame_levelupConf = GD:queryFameLevelUpById( self._data.level )
		self._text_grade:setString( L(fame_levelupConf.name) )

		local fameLvUpExp = tonumber( fame_levelupConf.exp )
		if 0 >= fameLvUpExp then -- 上限了？
			self._num:setString( "(MAX)" )
		else
			self._num:setString( table.concat( { "(", self._data.exp, "/", fameLvUpExp, ")" } ) )
		end

		self._loadingBar:setPercent( self._data.exp/fameLvUpExp * 100 )

		self:setNewFlagVisible( UD:isNewGotRenown( self._data.id ) )
	end
end

function ClassRef:refreshRedPoint()
	if self._data then
		self:setNewFlagVisible( UD:isNewGotRenown( self._data.id ) )
	end
end

function ClassRef:isSelected()
	return self._isSelected
end
function ClassRef:setSelected(b)
	self._isSelected = b
end

-- new标记可见性
function ClassRef:setNewFlagVisible(b)
	self._ui["Panel/Btn_s/dot"]:setVisible( b )
end

function ClassRef:setClickHandler(func)
	self._onClick = func
end

function ClassRef:setParentRender(p)
	self._parentRender = p
end

return ClassRef
